import os

from agent.common.system import sysCommand
from agent.common.tools import ConfigFile
from agent.feature.base import Feature


class Irqbalance(Feature):
    __domain__  = "irqbalance"
    __feature__ = "banned_cpus"
    
    def __init__(self) -> None:
        super().__init__(self.__domain__, self.__feature__)
        
        self.irq_config_path = "/etc/sysconfig/irqbalance"
        if not os.path.exists(self.irq_config_path):
            raise Exception("irqbalance config file {} is not exists".format(self.irq_config_path))
        else:
            self.config_file = ConfigFile(self.irq_config_path)
            
    def set_value(self, value):
        self.config_file.writeValue(key = self.__feature__, value = value)
        sysCommand("systemctl try-restart irqbalance", log = True)
        self.config_file.removeDuplicate()
    
    def get_value(self):
        return self.config_file.readValue(key = self.__feature__)